package com.thinking.dubbo.config;

import cn.hutool.core.util.StrUtil;
import com.thinking.dubbo.common.TtlThreadUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName GlobalInterceptor
 * @Description TODO
 * @Author tangsixiang@gmail.com
 * @Date 2023/6/5 14:36
 * @Version 1.0
 */

@Slf4j
public class GlobalInterceptor   implements HandlerInterceptor  {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String lang = request.getHeader("lang");
        if(StrUtil.isNullOrUndefined(lang)){
            lang="zh_TW";
        }
        TtlThreadUtil.getThreadLocal().set(lang);
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
